package com.example.demo.controller;

import com.example.comon.domain.LoginUser;
import com.example.comon.domain.R;
import com.example.comon.utils.UserUtil;
import com.example.demo.domain.Bo.AddOvertimeBo;
import com.example.demo.domain.Bo.OvertimeListBo;
import com.example.demo.domain.Overtime;
import com.example.demo.domain.Vo.OvertimeVo;
import com.example.demo.service.IOvertimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/overtimeApplication")
@Api(value = "overtimeApplication",tags = "加班申请控制器")
public class OvertimeApplicationController {

    @Autowired
    private IOvertimeService overtimeService;


    @GetMapping("/getOvertimeList")
    @ApiOperation("获取加班申请列表")
    public R<List<OvertimeVo>> getOvertimeList(OvertimeListBo bo){
        Overtime overtime = new Overtime();
        overtime.setOvertimeId(bo.getEmployeeId());
        List<OvertimeVo>list = overtimeService.selectOvertime(overtime);
        return R.success(list);
    }

    @PostMapping("/addOvertime")
    @ApiOperation("增加加班申请")

    public R<Overtime> addOvertime(@RequestBody AddOvertimeBo bo){
        Overtime overtime = new Overtime();
        overtime.setEmployeeId(bo.getEmployeeId());
        overtime.setJobContent(bo.getJobContent());
        overtime.setOvertimeStartTime(bo.getOvertimeStartTime());
        overtime.setOvertimeEndTime(bo.getOvertimeEndTime());
        overtime.setOvertimeReason(bo.getOvertimeReason());
        overtime.setExpectedResult(bo.getExpectedResult());
        overtime.setOvertimeDays(bo.getOvertimeDays());
        overtimeService.insertOvertime(overtime);
        return R.success(overtime);
    }

    @PostMapping("/updateOvertinmeById")
    @ApiOperation("修改加班申请")
    public R updateOvertimeById(@RequestBody Overtime overtime) {
        overtimeService.updateOvertimeById(overtime);
        return R.success();
    }

    @DeleteMapping("/delOvertimeById")
    @ApiOperation("删除加班申请")
    public R delOvertimeById(long overtimeId){
        overtimeService.delOvertimeById(overtimeId);
        return R.success();
    }

}
